<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>广告图片管理</title>
	<meta name="decorator" content="default"/>
    <script type="text/javascript" src="${ctxStatic}/plupload/plupload.full.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			var uploader = new plupload.Uploader({
				browse_button : "browse",
				url : "${ctx}/advertising/advertisingPohoto/upload",
				flash_swf_url : "${ctxStatic}/Moxie.swf",
				silverlight_xap_url : "${ctxStatic}/Moxie.xap",
				filters : { max_file_size : "100mb" }
            });
			
			uploader.init();
			
			uploader.bind("BeforeUpload", function(uploader, file){
				console.log("file:" + file);
			});
			
			uploader.bind("FilesAdded", function(uploader, file){
				$("#ossfile").empty();
				uploader.selFile = file;
				//对上传图片做限制
				debugger
				if(file[0].size > 500000){
					alert("请上传小于500kb的图片")
					return false;
				}
				
				$("#photoName").val(file[0].name);
				$("#photoType").val(file[0].type);
				
			});
		/* 	 //绑定各种事件，并在事件监听函数中做你想做的事
	        uploader.bind('FilesAdded',function(uploader,files){
				//每个事件监听函数都会传入一些很有用的参数，
				//我们可以利用这些参数提供的信息来做比如更新UI，提示上传进度等操作
	            $("#ossfile").empty();
				plupload.each(files, function(file) {
					console.log(uploader);
					uploader.selFile = file;
					//对上传图片做限制
					if(file.size > 500000){
						alert("图片大于400kb")
						return false;
					}
					if ( file.name != "") {
						
						$("#fileName").val(file.name);
						$("#sizes").val(plupload.formatSize(file.size));
					}
					//得到文件夹的名字   保存在div中
					document.getElementById('ossfile').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ')<b></b>' + '<div class="progress" id="ss"><div class="progress-bar" style="width: 0%"></div></div>' + '</div>';			    
				});
		    }); */
			
			uploader.bind("UploadProgress", function(uploader, file){
				
			});
			
			document.getElementById("btnSubmit").onclick = function(){
				uploader.start();
			}
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/advertising/advertisingPohoto/">广告图片列表</a></li>
		<li class="active"><a href="${ctx}/advertising/advertisingPohoto/form?id=${advertisingPohoto.id}">广告图片<shiro:hasPermission name="advertising:advertisingPohoto:edit">${not empty advertisingPohoto.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="advertising:advertisingPohoto:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="advertisingPohoto" action="${ctx}/advertising/advertisingPohoto/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">图片名称：</label>
			<div class="controls">
				<form:input path="photoName" htmlEscape="false" maxlength="255" class="input-xlarge " readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">图片类型：</label>
			<div class="controls">
				<form:input path="photoType" htmlEscape="false" maxlength="255" class="input-xlarge " readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">跳转链接：</label>
			<div class="controls">
				<form:input path="photoUrl" htmlEscape="false" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">广告位置：</label>
			<div class="controls">
				<form:select path="photoPosition">
				    <option>--请选择--</option>
				    <c:forEach items="${advertisingPohoto.dictList }" var="dict">
				        <form:option value="${dict.value }" >${dict.label }</form:option>
				    </c:forEach>
				</form:select>
			</div>
		</div>
		<div class="control-group">
            <label class="control-label">图片：</label>
            <div class="controls">
                <p id="ossfile"></p>
                <input type="button" value="选择文件"  id="browse" accept=".BMP,.JPG,.JPEG,PNG,GIF" class="color ci_width_90 zl_loading" />
            </div>
        </div>
		<div class="form-actions">
			<shiro:hasPermission name="advertising:advertisingPohoto:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>